<?php


namespace app\common\service;


use app\common\model\GroupModel;
use app\common\model\GroupRoleModel;
use app\common\model\RoleModel;
use app\common\model\UsersModel;

class CacheWarmUp
{
    public function __construct()
    {

    }

    public static function group()
    {
        $groupModels = GroupModel::select();
        if ($groupModels->isEmpty()) {
            $data = [];
        } else {
            $data = [];
            foreach ($groupModels as $item) {
                $data[] = $item->toArray();
            }
        }
        //Redis::tableSet(__FUNCTION__, $data);
        return $data;
    }

    public static function role()
    {
        $roleModels = RoleModel::select();
        if ($roleModels->isEmpty()) {
            $data = [];
        } else {
            $data = [];
            foreach ($roleModels as $item) {
                $data[] = $item->toArray();
            }
        }
        //Redis::tableSet(__FUNCTION__, $data);
        return $data;
    }

    public static function users()
    {
        $userModels = UsersModel::select();
        if ($userModels->isEmpty()) {
            $data = [];
        } else {
            $data = [];
            foreach ($userModels as $item) {
                $data[] = $item->toArray();
            }
        }
        //Redis::tableSet(__FUNCTION__, $data);
        return $data;
    }

    public static function group_role()
    {
        $groupRoleModels = GroupRoleModel::select();
        if ($groupRoleModels->isEmpty()) {
            $data = [];
        } else {
            $data = [];
            foreach ($groupRoleModels as $item) {
                $data[] = $item->toArray();
            }
            //halt($data);die;
        }
        //Redis::tableSet(__FUNCTION__, $data);
        return $data;
    }
}